#!/bin/bash
set -e


sudo apt install -y \
build-essential yasm cmake libtool libc6 libc6-dev unzip wget \
libnuma1 libnuma-dev libx264-dev libx265-dev libfaac-dev libssl-dev

git clone https://github.com/FFmpeg/nv-codec-headers.git
pushd nv-codec-headers
git checkout n11.1.5.0
sudo make install
popd

wget https://ffmpeg.org/releases/ffmpeg-4.2.5.tar.bz2
tar -xjf ffmpeg-4.2.5.tar.bz2
pushd ffmpeg-4.2.5
sed -i 's#_30#_75#' configure
./configure \
--enable-nonfree \
--enable-gpl \
--enable-shared \
--enable-ffmpeg \
--enable-ffplay \
--enable-ffprobe \
--enable-libx264 \
--enable-libx265 \
--enable-cuda-nvcc \
--enable-nvenc \
--enable-cuda \
--enable-cuvid \
--enable-libnpp \
--extra-libs="-lpthread -lm" \
--extra-cflags=-I/usr/local/cuda/include \
--extra-ldflags=-L/usr/local/cuda/lib64 
make -j8
sudo make install
popd 


git clone https://gitee.com/xia-chu/ZLMediaKit
pushd ZLMediaKit
git submodule update --init
mkdir build
cd build
cmake ..
make -j4
popd

mkdir ZLM
pushd ZLM
cp ../ZLMediaKit/release/linux/Debug/MediaServer .
cp ../ZLMediaKit/release/linux/Debug/config.ini .
popd